#include "time.h"

namespace porlarday
{
	Time::Time(int year, int month, int day, int hour, int minute, int second)
	{
		if (year < 1900)
			year = 1900;
		if (month < 0 || month > 11)
			month = 0;
		if (day < 1 || day > 31)
			day = 1;
		if (hour < 0 || hour > 23)
			hour = 0;
		if (minute < 0 || minute > 0)
			minute = 0;
		if (second < 0 || second > 60)
			second = 0;

		std::tm set_time;
		set_time.tm_year = year;
		set_time.tm_mon = month;
		set_time.tm_mday = day;
		set_time.tm_hour = hour;
		set_time.tm_min = minute;
		set_time.tm_sec = second;

		unix_time_ = std::mktime(&set_time);
	}

	fbstring Time::ToString(fbstring string)
	{
		std::tm* tm_time = std::localtime(&unix_time_);
		std::stringstream ret_str;
		ret_str << std::put_time(tm_time, string.data());
		return ret_str.str();
	}
}